package com.cyj.dream.auth.handler;


import com.cyj.dream.auth.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 用户未登录处理类
 * @BelongsProject: dream-DreamChardonnay
 * @BelongsPackage: com.dream.DreamChardonnay.handler
 * @Author: ChenYongJia
 * @CreateTime: 2021-4-1 09:28:33
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@Component
public class UserAuthenticationEntryPointHandler implements AuthenticationEntryPoint {

    /**
     * 用户未登录返回结果
     *
     * @Author ChenYongJia
     * @CreateTime 2020-5-11 09:47:53
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
        log.info("-----------用户未登录返回结果-----------");
        ResultUtil.responseJson(response, ResultUtil.resultCode(401, "尚未登录，请先登陆后进行操作！"));
    }

}
